package com.bzy.common.aop.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bzy.common.bean.Result;
import com.bzy.common.util.LoggerUtil;
import com.bzy.common.util.local.ExceptionUtil;
import com.bzy.common.util.local.ThreadLocalUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;

@ControllerAdvice
public class ControllerAdviceHandler extends AbstractJsonpResponseBodyAdvice {

    private Logger logger = LoggerFactory.getLogger(ControllerAdviceHandler.class);

	public ControllerAdviceHandler() {
		super("callback");
	}

	@ResponseBody
	@ExceptionHandler(Exception.class)
	public Result errorResponse(Exception exception, HttpServletRequest request, HttpServletResponse response) {
        Result o = ExceptionUtil.resolveException(exception);

		String exceptionString = ExceptionUtil.getExceptionContent(exception);
		logger.error("致命错误....."+exceptionString);

		ThreadLocalUtil.setExceptionString(exceptionString);

		return o;
	}

}
